package dynamicStreaming
{
	import flash.display.Stage;
	
	import org.osmf.elements.VideoElement;
	import org.osmf.media.MediaPlayerSprite;
	import org.osmf.net.DynamicStreamingItem;
	import org.osmf.net.DynamicStreamingResource;

	public class DynamicStreamingExample
	{
		/**
		 *Delivery quality, specifically how well a player responds to bandwidth changes, is a key differentiator of media players. 
		 * Dynamic Streaming helps your player adapt to changing network conditions.
		 * With Dynamic Streaming, when the player senses a network bandwidth change, 
		 * it responds by switching playback to a content file with a more appropriate bit rate. 
		 * Dynamic Streaming requires you to have multiple bit rate (MBR) versions of content for the player to switch among.
		 *  When you provide MBR content, a network experiencing a temporary reduction in bandwidth does not have to pause playback for the user.
		 *  Instead, the player shifts to using a lower bit rate version of the content that is playing.
		 *  If the player does not find multi-bitrate versions of content, Dynamic Streaming does not function. 
		 */
		
		
		/**
		 *	Managing buffer size for RTMP and HTTP streams
			OSMF does not set a default size for the RTMP or HTTP stream buffer. 
			You must set MediaPlayer.bufferTime to a size appropriate to the needs of your player.
			*	For RTMP Dynamic Streaming/MBR content, set the buffer size to 8 seconds or greater. 
			  	This applies to any RTMP dynamic stream, whether live or recorded. 
			   	For live MBR content, you must set the buffer size to a nonzero value or MBR switching fails.
			*	For RTMP streams that are not dynamic/MBR, set the buffer size to between 2 and 4 seconds.
			*	For HTTP Dynamic Streaming, see the sample HTTPStreamingNetLoaderWithBufferControl.
			 * as in the OSMFPlayer source repository for an example of managing buffer size. 
		 */
		private var root:Stage;
		
		public function DynamicStreamingExample(root:Stage)
		{
			this.root = root;
			var mediaPlayerSprite:MediaPlayerSprite = new MediaPlayerSprite();
			
			var videoElement:VideoElement = new VideoElement();
			
			/**
			 * By convention, most rtmp URLs do not use file extensions.
			 */
			var dynStreaming:DynamicStreamingResource = new DynamicStreamingResource("rtmp://localhost/vod/");
			
			/**
			 * The first two parameters of each DynamicStreamingItem specify stream name and bitrate and are required.
			 * The second two parameters of each DynamicStreamingItem are optional;
			 * they specify the stream's width and height, in that order.
			 */
			dynStreaming.streamItems = Vector.<DynamicStreamingItem>
				(
					[  new DynamicStreamingItem("mp4:localhost/vod/sample1_150kbps.f4v", 150, 768, 428),
						new DynamicStreamingItem("mp4:localhost/vod/sample1_500kbps.f4v", 500, 768, 428),
						new DynamicStreamingItem("mp4:localhost/vod/sample1_700kbps.f4v", 700, 1024, 522),
						new DynamicStreamingItem("mp4:localhost/vod/sample1_1000kbps.f4v", 1000, 1024, 522),
						new DynamicStreamingItem("mp4:localhost/vod/sample1_1500kbps.f4v", 1500, 1280, 720)
					]
					/*[ new DynamicStreamingItem("mp4:localhost/vod/demo_768x428_24.0fps_408kbps.mp4", 408, 768, 428),
					  new DynamicStreamingItem("mp4:localhost/vod/demo_768x428_24.0fps_608kbps.mp4", 608, 768, 428),
					  new DynamicStreamingItem("mp4:localhost/vod/demo_1024x522_24.0fps_908kbps.mp4", 908, 1024, 522),
					  new DynamicStreamingItem("mp4:localhost/vod/demo_1024x522_24.0fps_1308kbps.mp4", 1308, 1024, 522),
					  new DynamicStreamingItem("mp4:localhost/vod/demo_1280x720_24.0fps_1708kbps.mp4", 1708, 1280, 720)
					]*/
				);
			
			videoElement.resource = dynStreaming;
			root.addChild(mediaPlayerSprite);
			
			mediaPlayerSprite.media = videoElement;
		}
	}
}